/*
 * @Author: xiaosihan 
 * @Date: 2023-09-19 16:52:47 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-06-07 22:26:54
 */

import utils from "@utils";
import metalMaterial from "@views/materials/metalMaterial";
import { Group, MeshLambertMaterial } from "three";
import threeLoader from "three-base/threeLoader";


// 加载  stl 模型
export default class StlMesh extends Group {

    constructor(stlUrl?: string) {
        super();
        stlUrl && this.loadModel(stlUrl);

        this.addEventListener("dbclick", () => {
            utils.editorMaterial(this.material);
        });

    }

    //three事件
    userData = {
        cursor: "pointer",
        enableEvent: true
    };

    material = metalMaterial.clone();

    async loadModel(url: string) {
        const mesh = await threeLoader.loadModel(url);
        this.add(mesh);
        this.dispatchEvent({ type: "loaded" } as any);
    }

}

